[Project Catch 'Em All - Developer Reference]

The sole purpose of this document is to help define the developing bounds of this game. The system is 100% custom and has some rules to follow if you want everything to work properly.
In order to follow this without too much confusion, it's assumed that you have knowledge of MUGEN CNS and basic programming concepts.
This isn't an intro to mugen coding or a tutorial by any means.

----------------------------------------------------------
[Variables]
Variables can be split into two groups: system and user.

*System Variables*

System variables are used by the system and shouldn't be modified unless otherwise stated.

var(0) = ATB Gauge Max
	- This is the maximum value that the ATB bar is at any time.
	- This changes and is set at the very beginning of a move.
var(1) = ATB Gauge Current Value
	- This is the current value the ATB bar has at any time.
	- DON'T modify this at all. The system handles it all times.
var(2) = ATB Gauge Modifier
	- This value can be set within a move to change the recovery rate of the ATB Gauge.
	- For example, Scyther's Agility sets this value to increase the rate of recovery for 3 moves. After those three moves are up, it is set back to 0.
	- Don't set this to a ridiculously high number because it's used like this:
		- current_value := current_value + 1 + var(2)
var(3) = AI Attack Index.
	- When the AI chooses an attack, it's stored in this variable.
	- Don't modify this value.
var(4) = Status Effect
	- 1 = Burn
	- 2 = Paralysis
	- 3 = Poison
	- 4 = Sleep
	- 5 = Freeze
	- 6 = Bad Poison [NOT IMPLEMENTED]
	- 7 = Confusion [NOT IMPLEMENTED]
	- 8 = Curse [NOT IMPLEMENTED]
var(5) = Attacking Enemy's ID
	- Used for reading data from attack enemy
	- Don't modify this value.
var(6) = Total Damage Done (per hit)
	- Post calculated damage amount
	- Don't change this value unless you have post-calculated damage you intend on showing, e.g. recoil damage
var(7) = AI Attack Threshold
	- Used to count ticks before the AI can attack. Currently counts to 200 before the enemy can attack.
	- Don't modify this value.
var(8) = Special Move
	- If this is set to 1, the move in question is "Special" and will use Special Attack and Special Defense stats instead of Attack and Defense, or will become a move that inflicts a set amount of damage if set to 2.
var(9) = Move's Accuracy
var(10) = Attack Stat to Increase/Decrease by Level
var(11) = S.Attack Stat to Increase/Decrease by Level
var(12) = Defense Stat to Increase/Decrease by Level
var(13) = S.Defense Stat to Increase/Decrease by Level
var(14) = Speed Stat to Increase/Decrease by Level
var(15) = Accuracy Stat to Increase/Decrease by Level
var(16) = Evasion Stat to Increase/Decrease by Level
var(17) = Critical Rate to Increase by Level
var(18) = -UNUSED BY CHARACTER/SYSTEM-
var(19) = Throwaway Variable, used for any pokemon that uses quick-calculations on opponents (Difference between previous HP and resulting HP, etc)
var(20) = Item State:
	- 0 = Unused
	- 1 = Unused (Sticky Hold)
	- 2 = Unused (Klutz)
	- 3 = Used Consumable Item
	- 4 = Used Held Item
	- 5 = Used Held Item (Sticky Hold)
	- 6 = Unusable (Embargo)
	- 7 = Unusable (Magic Room)
	- 8 = Removed and cannot regain
var(21) = Used Item Effect:
	- 0 = None
	- 1 = Full Restore
	- 2 = X Attack 2
	- 3 = X Defence 2
	- 4 = X Speed 2
	- 5 = X Sp.Atk 2
	- 6 = X Sp.Def 2
	- 7 = X Accuracy 2
	- 8 = X Evade 2 [DOESN'T EXIST IN ACTUAL GAME]
	- 9 = Dire Hit 2
	- 10 = White Herb (Removes all lowered stats instantly)
	- 11 = Grip Claw ("Binding" move's active turns = 8, "Multi-strike" move's active hits becomes maximum)[NOT IMPLEMENTED]
	- 12 = Big Root (30% healing boost for all moves that heal the user)
	- 13 = Rock Collection (Weather turns active = 8 turns)
	- 14 = Terrain Extender (Terrain/Surge turns active = 8 turns)
	- 15 = Leftovers
	- 16 = Assault Vest (Special Defence +50%, prevents use of status moves) [NOT IMPLEMENTED]
	- 17 = Life Orb (Move's Power = +30%, adds recoil effect of 10% of Max HP) [NOT IMPLEMENTED]
	- 18 = Weakness Policy (If hit by weakness, ATK/S.ATK increased by 2 levels, but only once)
	- 19 = Shell Bell (Recover 1/4 of damage dealt as HP) [NOT IMPLEMENTED]
	- 20 = Safety Goggles (Immune to weather damage, the effects of the enemy's "spore"/"powder"/"sand" moves, and accuracy-reduction moves.) [NOT IMPLEMENTED]


var(22) = Confusion (User randomly uses moves that isn't the current one selected) [NOT IMPLEMENTED]
var(23) = Torment / Taunt / Both [NOT IMPLEMENTED]
var(24) = Magic Room [NOT IMPLEMENTED]
var(25) = Reflect/Light Screen/Both/Aurora Veil [NOT IMPLEMENTED]
var(26) = Gravity [NOT IMPLEMENTED]
var(27) = Safeguard
var(28) = Encore/Disable Move Locked Into [NOT IMPLEMENTED]
var(29) = Encore/Disable Turns [NOT IMPLEMENTED]
var(30) = Miss Flag
	- 1 if the move is calculated to miss; 0 otherwise
var(31) = Crit Hit Flag
	- 1 if the current move is a crit; 0 otherwise
var(32) = -UNUSED BY CHARACTER/SYSTEM-
var(33) = Periodic Damage timer
var(34) = Current Terrain
	- 0 = None (No Terrain)
	- 1 = Grassy Terrain
	- 2 = Misty Terrain
	- 3 = Electric Terrain
	- 4 = Psychic Terrain
var(35) = Terrain Changer
var(36) = Total Calculated Damage (of total hits before recover)
	- This isn't in use yet, but might be in the future. The var does store the right value though.
var(37) = Weather
	- 0 = Clear Skies (No Weather)
	- 1 = Harsh Sunlight
	- 2 = Extremely Harsh Sunlight
	- 3 = Rain
	- 4 = Heavy Rain
	- 5 = Sandstorm
	- 6 = Hail
	- 7 = Fog
	- 9 = No Weather, used to prevent weather variables from constantly setting weather.
var(38) = Weather Setter by all players
	- 
var(39) = Sleep/Freeze timer
	- This is set when the victim gains these status, and counts down after filling the ATB to Max a number of times (Sleep), or every second or after taking direct damage (Freeze).

fvar(0) = Player position.
	- At the beginning of the round, this value is recorded so the pokemon always return to their spots after being hit away from them, or moving away during an attack.
	- Don't modify this.
fvar(1) = Current Damage Modifier Value
	- This is used for affinities.
	- Don't modify this value.
fvar(2) = Critical Rate
	- This is the critical rate percentage
fvar(3) = Crit Damage Modifier
	- 1.5 if crit triggered; 1.0 otherwise
fvar(4) = Attack Stat
fvar(5) = Special Attack Stat
fvar(6) = Defense Stat
fvar(7) = Special Defense Stat
fvar(8) = Accuracy Stat
fvar(9) = Evasion Stat
fvar(10~29) + fvar(32) = Type weakness rates
fvar(30) = Calculated Hit Rate
fvar(31) = Weather modifier for use in damage calculations
fvar(33) = Terrain modifier for use in damage calculations
fvar(34) = Attack Stat to influence with Increase/Decrease by Percentage
fvar(35) = S.Attack Stat to influence with Increase/Decrease by Percentage
fvar(36) = Defense Stat to influence with Increase/Decrease by Percentage
fvar(37) = S.Defense Stat to influence with Increase/Decrease by Percentage
fvar(38) = Speed Stat to influence with Increase/Decrease by Percentage
fvar(39) = Accuracy Stat to influence with Increase/Decrease by Percentage

*User Variables*
User variables are variables that you can use for anything in your character. There's not much restriction here, you can use these for whatever you want. In most cases, for advanced attacks, you'll need these.

var(40+)
fvar(40+)

NOTE: This is the fully-updated version of all variables being used by the system. Unless otherwise stated, only use the above list to remind yourself what variable is being used, regardless of other character's state files.

=-==========-==========-==========-=-==========-==========-==========-=-==========-==========-==========-
[Attacks]
Attacks are the bulk of each pokemon. They have 4 each that can be anything you want, within reason. Keep in mind that it's recommended to use moves from the main line of Pokemon games instead of branch-line games.

Here are some examples of what you could do and (morally) couldn't do:


Pikachu with Volt Tackle, gotten from an evolved Pichu: OK
Pikachu with Surf from Pokemon Stadium, transferred to the handheld games: Maybe
Gengar with both Levitate and Cursed Body, despite the latter replacing the former: OK


------------------------------------------------------------------------
*ATB Gauge*
At the beginning of each attack, you need to set the following values for that attack, with an explanation for all values set:

[State 5##, Set ATB]
type = Null
trigger1 = !time
trigger1 = var(0):=floor((200)*fvar(38)) && var(8):=1 && var(9):=floor((100)*fvar(39)) && fvar(2):=0

var(0): Sets the maximum ATB value to the number specified. The system resets the current ATB value to 0 when you choose an attack, and fills up at a rate of 60 points per one second. At the beginning of this move, you'll have an ATB of 0/200 in this case. Set ATB higher for a longer recovery time and lower for a shorter recovery time.
var(8): Sets whether the move is Physical, Special, or a move that ignores all stats. Choose 0 for Physical, 1 for Special, or 2 to make moves that inflicts a set amount of damage. When either is set, it changes the damage calculations to use the relevant stat (Attack or S.Attack) to determine damage dealt, but setting at 2 will remove said calculations (including whether the move deals critical damage or not). If removed from the state, it assumes the default value of 0 will be used.
var(9): Sets the move's accuracy. If the move itself doesn't use accuracy, set this number to 999, otherwise the system will cause the move to display the "miss" message when your accuracy is lowered by an effect in play (Mist Weather, etc).
fvar(2): Sets the move's Critical chance in a float variable. If removed from the state, it assumes the default chance of 6.25% will be used. If the move itself doesn't use Critical chance, set this number to 0, otherwise the system will cause the move to critical even if it doesn't hurt the opponent.


As an example, I want to make Stone Edge. It's a physical move that has a higher chance to critical, has 80% accuracy, and should be slow to recover from using it.

[State 500, Set ATB]
type = Null
trigger1 = !time
trigger1 = var(0):=floor((300)*fvar(38)) && var(8):=0 && var(9):=floor((80)*fvar(39))


--------------------------------

NOTE: As per Beta 5, the coding on critical hits have now been reworked, and will require the user to add the following lines of states to implement "High Critical Hit Ratio" moves:

This needs to be in Statedef -3:

[State Helper]
type = Helper
trigger1 = numhelper(800) = 0
stateno = 800
id = 800
name = "Critical Level Checker"
helpertype = Normal
pos = 0,-2
postype = p1
facing = ifelse(facing = 1,1,-1)
ownpal = 1
ignorehitpause = 1


This needs to be in the character's state files:


; Critical Level Checker
[Statedef 800]
movetype = I
velset = 0,0
ctrl = 0
sprpriority = 2
anim = 9999; Pokemon's Blank Anim

[State NotHitBy]
type = NotHitBy
trigger1 = 1
value = SCA,NA,SA,HA,NP,SP,HP,NT,ST,HT

[State PlayerPush]
type = PlayerPush
trigger1 = 1
value = 0

[State VarSet];Records original Critical Rate
type = VarSet
trigger1 = root,stateno != [500,1999]
v = 47
value = root,var(17)

[State VarSet];Resets temporarily increased Critical Rate
type = VarSet
trigger1 = root,stateno != [500,1999]
v = 48
value = 0

[State VarSet];State to temporarily increase Critical Rate at
type = VarSet
triggerall = root,stateno = 500;modify this to the stateno with the temporary increased critical rate.
trigger1 = root,time = 1
v = 48
value = 1

[State ParentVarSet];Temporarily increases Critical Rate
type = ParentVarSet
triggerall = root,stateno = 500;modify this to the stateno with the temporary increased critical rate.
trigger1 = root,time = 1
v = 17
value = root,var(17)+var(48)

[State ParentVarSet];Turns off increased Critical Rate after check is done in statedef -2
type = ParentVarSet
triggerall = root,stateno = 500;modify this to the stateno with the temporary increased critical rate.
trigger1 = root,time = 3
v = 17
value = root,var(17)-var(48)

[State VarSet];Turns off increased Critical Rate after check is done in statedef -2
type = VarSet
triggerall = root,stateno = 500;modify this to the stateno with the temporary increased critical rate.
trigger1 = root,time = 3
v = 48
value = 0

--------------------------------

How it works is this: After the user has selected a move, the system checks on the user's 2nd tick if the user has attained a critical hit. The above code temporarily adds an extra level to your critical rate, leaving enough time for the system to detect criticals, then removes it quickly. Thus, you have the basic function of the "High Critical Hit Ratio" moves.

However, to prevent the game from skipping calculations and other state-based things, you must leave enough time for the states to calculate everything. To do this, you should leave at least two ticks so the system calculates everything.

Here's an example of a moving attack that leaves time to calculate things:

[State ChangeState]
type = ChangeState
triggerall = time >= 3
trigger1 = P2BodyDist X <= 10
trigger2 = time >= 300
value = 511


------------------------------------------------------------------------
*State Numbers*
500,510,520,530 are reserved for attacks. It's imperative that you keep true to these values. The select menu uses them explicitly; if you use anything else, the system won't be able to perform your attack.

The menu has four attacks that you choose from. Each state corresponds to a move:
1st move = 500
2nd move = 510
3rd move = 520
4th move = 530

Attacks can span over multiple states too. As long as your attack is within 10 states (all should be), you'll be fine.
For example, 500 can be the start of Attack 1, that leads into 501, 502, and ends at 503. That's perfectly fine.
If you run out of room despite this, you can even span your attacks past this range, as long as the starting state for the attack is either of the four reserved state numbers. For example, 500 is the start of Attack 1, that leads into 1000, 1454, and ends at 1950. If you do this, note that you shouldn't go any higher or lower than state [500-1999] for the purpose of the system.


------------------------------------------------------------------------
*Ending states*
In order to return your character to their spot, all you have to do is send them to State 0. For example:
[State 5##, Stand State]
type = ChangeState
trigger1 = !AnimTime
value = 0
ctrl = 1

If the system detects that the character is not in their spot, it will force them into their "run back" state. You don't have to worry about that ever. Just send them back to State 0 when done.

------------------------------------------------------------------------
*Damage*
We code damage values to match that of the actual attack from the game. For example:

Flamethrower: http://bulbapedia.bulbagarden.net/wiki/Flamethrower
90 damage. Since a flamethrower would be particle based (spawn many helpers that each does its own damage), we'd split 90 by the number of flame particles we're spawning. If you're spawning 5 flame particles, then each one would do 18 damage each.
If the move is only going to hit once, then it would do the full damage of 90.

To code said move, we use a state that applies accuracy and a Hitdef state.

; Apply hit rate
[State ]
type = StateTypeSet
trigger1 = var(30)
movetype = I

Hit Rate is calculated and stored in var(30). This sets the attack to Idle, causing the resulting move to not hit anything and miss if your accuracy is lower than the random number generator's value at the time. If the attack uses projectiles, use "root,var(30)" instead of the original trigger, and place this and the Hitdef in the projectile's Statedef. If the move doesn't use accuracy, get rid of this state.


[State ###, HitDef]
type = HitDef
trigger1 = time = 0                          ; Change to what you want the move to be like.
attr = A,NA                                  ; Unused
hitflag = MAFD                               ; Unused
guardflag = MA                               ; Unused
animtype = heavy                             ; Unused
air.animtype = heavy                         ; Unused
damage = 1,0                                 ; The system requires this to be 1 so that damage calculations can be carried out properly.
priority = 1,Hit                             ; Attack Priority, see below the state for details.
pausetime = 0,0                              ; Set to 0,0 to prevent certain bugs from happening due to this controller.
sparkno = -1                                 ; Change to what effects you want to use.
guard.sparkno = S3100                        ; Change to what effects you want to use.
sparkxy = 0,0                                ; Change to what effects you want to use.
hitsound = S530,1                            ; Change to what effects you want to use.
guardsound = 2,0                             ; Unused
ground.type = High                           ; Unused
ground.slidetime = 20                        ; Change to what you want the move to be like.
ground.hittime = 20                          ; Change to what you want the move to be like.
air.hittime = 20                             ; Change to what you want the move to be like.
ground.velocity = 0,0                        ; Change to what you want the move to be like.
air.velocity = 0,-1                          ; Change to what you want the move to be like.
sprpriority = 1                              ; Change to what you want the move to be like.
fall = 0                                     ; Change to what you want the move to be like.
air.fall = 1                                 ; Change to what you want the move to be like.
palfx.time = 20
palfx.add = 240,50,0
palfx.mul = 250,224,120
palfx.sinadd = 110,55,85,10
palfx.invertall = 0
palfx.color = 0
fall.envshake.time = 0                       ; Do not remove
fall.envshake.ampl = 11 ; Fire               ; Move Type. Relates to the variables used in the "Set Type Weaknesses" state, with fvar(10) being Normal, fvar(11) being Fire, etc. Set the number to the type you want, without the "fvar()" part.
fall.envshake.freq = ID                      ; If the attack uses projectiles in the form of Helpers, use "root,ID" in the projectile's state instead of the original value.
fall.envshake.phase = floor(9*1.5)           ; Move's power, divided by the amount of hits it deals. If it's the same type as the user, use floor(#*1.5) to implement "Same Type Attack Boost" (STAB), otherwise leave that out by putting in a standard number.

Just like any other Hitdef state, you can add other bits of code to spice the move up, like adding the code family "palfx" to change the colour of a hurt opponent.
In the event you want to code a move that inflicts a status or effect to an opponent without type clashes, but doesn't deal damage, refer to Beedrill's "Toxic Spikes".
In the event you want to code a move that inflicts a set amount of damage, set var(8) to 2, and then set the move's power to the damage you want to deal to the opponent ("Dragon Rage" always inflicts 40 damage, so put 40 as the value).

IMPORTANT: We don't use the damage parameter of the HitDef due to a bug in mugen's calculations. Set damage=1,0 (or anything higher than 0) and use the fall.envshake.phase parameter instead. (See above)
The bug in mugen is that damage returned can never be greater than the life you have. Mugen manipulates what gets returned from gethitvar(damage), but not what gets returned by other variables, so we just use another one to get around it.


------------------------------------------------------------------------
*ATTACK PRIORITY*

In the same way that Pokemon use priority from certain moves to determine turn order (Quick Attack, Protect, etc), this game uses a Mugen's own priority to determine attacks that clash.

Here is a general chart to determine priority:

1: Physical moves that have no priority.
2: Physical moves that have +1 or more priority.
3: Status move in projectile form that deals no damage, no priority.
4: Projectile moves that aren't beams or can only hit once per hit.
5: Beam-based or full-screen projectile moves.
6: Counter/Mirror Coat-esque moves.

For example, "priority  = 2,Hit", is a physical hit with higher priority, like Quick Attack. If the opponent is using a lesser-priority move that attacks with their body directly, then the Quick Attack user will win if both players collide.

------------------------------------------------------------------------
*Attack Clash*
Most, if not all attacks clash in some sort of way. Most elemental, particle type effects have this ability. For example: Bubblebeam vs Flamethrower. They could cancel each other out or nullify damage.
All attacks involving launching some sort of projectile (helpers only) at the enemy are required to be hittable and cancellable. You will use HitOverride to make this happen.
In some cases, those attacks have "lives," or a specific number of times they can be hit before dying. For example: X-Scissor can take about 5 hits before being killed. Flame Wheel can take 3.
This is done with a variable that controls the life of the attack. HitOverride will send the helper back to its current state. At the top of the state, you check to see if prevstateno has a value and then
decrease your "lives" var by 1. When it's less than or equal to 0, you send the helper to a die state.

Example of single-life HitOverride:
[State 531, Hittable]
type = HitOverride
trigger1 = 1 
attr = SCA,AA,AT,AP
slot = 0
stateno = 532 ; Death State
time = 1
ignorehitpause = 1

Example of multiple-lives:
[State 531, Init Vars]
type = null
trigger1 = prevstateno && !time
trigger1 = var(10):=var(10)-1

[State 531, Hittable]
type = HitOverride
trigger1 = 1 
attr = SCA,AA,AT,AP
slot = 0
stateno = 531
time = 1
ignorehitpause = 1

[State 531, Die State]
type = ChangeState
trigger1 = var(10)<=0 || FrontEdgeDist < -40
value = 532


------------------------------------------------------------------------
*Reset Critical Damage*

There's an important state that needs to be known. This state is in Statedef -2, within common1.cns:

; Reset Crit
[State ]
type = Null
trigger1 = movetype!=A
trigger1 = fvar(3):=1.0


If any of your pokemon's statedef have their "movetype" NOT set at "A" OR your attack ends before the projectile[s] hit the opponent, your critical damage will be set to 1 for the entire state, dealing the same damage as a normal attack. To avoid this, set all of your statedef's Movetype to A, and make sure to leave enough time for projectiles to hit opponents before leaving the attack state, unless this is a repeating move that stops attacking after being hit.

------------------------------------------------------------------------
*Reset Calculated Hit Rate*

There's another important state that needs to be known. This state is in Statedef -2, within common1.cns:

; Calculate Hit Rate
[State ]
type = Null
triggerall = time=1 && (stateno=500 || stateno=510 || stateno=520 || stateno=530)
trigger1 = fvar(30):= (var(9)/100.0) * ( fvar(8)*1.0*ifelse(var(37)=7,0.6,1) / enemynear,fvar(9))
trigger1 = var(30):=(random/999.0)>fvar(30)


Though it's not important for the usual attack, if you're making something as dynamic as the move "Counter", be warned that your total hit rate will be re-calculated if you go back to the starting state of your attack. Instead, make a copy of the starting state, but get rid of the "[State 5##, Set ATB]" state and you should be fine.

------------------------------------------------------------------------
*Null States*

This is a reminder: Though the "Null" state controller does nothing, it is used throughout the game as a way to set multiple variables without using multiple "VarSet" and "VarAdd" states, which would create "code clutter" and thus cause the game to slow down. 

------------------------------------------------------------------------
*Pause/Superpause States*

WARNING: Don't use any of the two Pause/Superpause states. It may work fine now, but these states causes Mugen to crash later on.

------------------------------------------------------------------------
*HitDef - Pausetime Note*

If you use the "pausetime" controller to set a number within the "HitDef" State, it may cause the "fall" and "air.fall" controllers to fail. This is apparent if your attack sends the opponent directly upwards in the air and lands down on the ground. If you want to use the "fall" and "air.fall" controllers, make sure "pausetime" is set to 0,0 to avoid this bug.


=-==========-==========-==========-=-==========-==========-==========-=-==========-==========-==========-
[Getting Hit]
In order to keep things natural, I kept the default common states with some slight modifications here and there.
When adding your "get hurt sprite(s)" to the sff, all you need to do is set 5000,0 and/or 5000,1 to your pokemon's get hit sprites.
All the others should stay as KFM sprites because they're required by MUGEN, not by the system. If we didn't get debug flood from
removing them, I would. But, just follow this rule to avoid it.

Animations are handled like you would with any other character, but remember to keep the standing, moving, and relevant attack collisions in line with your get-hit collisions, and keep your get-hit collisions the same in every "hurt" animation to prevent certain attacks missing you due to irregular collisions. In addition, remember to set the ground.front and ground.back in the [Size] block of code to be slightly smaller than your collisions.

When editing Kung Fu Man, the standing animation will have an extra collision inside it, a smaller one. Though it may not be necessary for what you're trying to make, this is the minimum length/width/height that your get-hit collisions can be without any problems with foes connecting with their attacks.


Wall bounce, red hurt PalFX, and "squishiness" are all handled by the system.

=-==========-==========-==========-=-==========-==========-==========-=-==========-==========-==========-
[Status Effects]

Pokemon can get hit by various status from moves, abilities, and what-not. In order to code this, you need to add the following to a move's statedef:

1. Relevant states. This is used to get the enemy in a custom state, where the next piece of code will be more useful there. This example is for Cross Poison (10% chance to poison).

[State VarSet]
type = VarSet                    ; Type of State
trigger1 = Time = 0              ; When this should activate
v = 41                           ; User variables used
value = ifelse(random <= 99,1,0) ; random is from 0-999, so this simulates the 10% chance to activate this effect

[State TargetState]
type = TargetState
trigger1 = var(41) && Numtarget && movehit
value = 502                                ; Statedef to move the target(s) to.
ID = -1
ignorehitpause = 1

[State MoveHitReset] ; Prevents the target(s) from being locked in to the state until the attack ends.
type = MoveHitReset
trigger1 = movehit
ignorehitpause = 1

2. Enemy StateDef. This is used to afflict the status you want to inflict.

; Cross Poison Enemy
[StateDef 502]
movetype = H

[State ChangeAnim]
type = ChangeAnim 
trigger1 = 1
value = 5000      ; Relevant animation

[State NotHitBy]
type = NotHitBy
trigger1 = 1
value = SCA,NA,SA,HA,NP,SP,HP,NT,ST,HT

[State VelSet]
type = VelSet
trigger1 = 1
x = -3

[State VarSet]
type = VarSet
triggerall = var(4) = 0  ; If enemy has no status
trigger1 = time = 0      ; When this should activate
var(4) = 3               ; Poison Status

[State PalFX] ; Poison Effects
type = PalFX
trigger1 = time = 0
time = 30
add = 0,-200,0
mul = 256,256,256
sinadd = 40,80,40,10
invertall = 0
color = 256

[State SelfState]
type = SelfState
trigger1 = time >= 1
value = 5000


As for immunities, they are added in common1.cns. Permanent ones, like Fire-types being immune to Burn, only require the name of the pokemon to activate, but this file must not be edited by anyone except the main project administrators, so contact them about getting your pokemon's status immunities checked out.

Non-permanent ones, like the Immunity ability, only require you to put the following relative state in statedef -3 as they are of lesser priority:

[State VarSet]; Immunity (Immune to Poison)
type = VarSet
triggerall = Var(40) >= 1 ; Abilites must be on
trigger1 = var(4) = 3     ; Status must be Poison OR
trigger2 = var(4) = 6     ; Status must be Bad Poison
v = 4                     ; Status variable
value = 0                 ; Removes status


=-==========-==========-==========-=-==========-==========-==========-=-==========-==========-==========-
[Stat Increases/Reductions]

Pokemon can get hit by various stat increases/decreases from moves, abilities, and what-not. In order to code this, you need to add the following to a move's statedef:

1. Relevant states. This is used to get the enemy in a custom state, where the next piece of code will be more useful there. This example is for Flash Cannon (10% chance to reduce Special Defence by 1).

[State VarSet]
type = VarSet                    ; Type of State
trigger1 = Time = 0              ; When this should activate
v = 41                           ; User variables used
value = ifelse(random <= 99,1,0) ; random is from 0-999, so this simulates the 10% chance to activate this effect

[State TargetState]
type = TargetState
trigger1 = var(41) && Numtarget && movehit
value = 502                                ; Statedef to move the target(s) to.
ID = -1
ignorehitpause = 1

[State MoveHitReset] ; Prevents the target(s) from being locked in to the state until the attack ends.
type = MoveHitReset
trigger1 = movehit
ignorehitpause = 1

2. Enemy StateDef. This is used to afflict the status you want to inflict.

; Flash Cannon Enemy
[StateDef 502]
movetype = H

[State ChangeAnim]
type = ChangeAnim 
trigger1 = 1
value = 5000      ; Relevant animation

[State NotHitBy]
type = NotHitBy
trigger1 = 1
value = SCA,NA,SA,HA,NP,SP,HP,NT,ST,HT

[State VelSet]
type = VelSet
trigger1 = 1
x = -3

[State PalFX]
type = PalFX
triggerall = var(13) >= -5 ; If enemy's Special Defence level is greater than -5
trigger1 = time = 0        ; When this should activate
time = 20
add = 40,-70,-200
mul = 256,256,256
sinadd = 40,30,0,10
invertall = 0
color = 256

[State Explod]
type = Explod
triggerall = var(13) >= -5 ; If enemy's Special Defence level is greater than -5
trigger1 = time = 0        ; When this should activate
anim = F42
pos = 0,10
postype = p1
removetime = -2
pausemovetime = 0
sprpriority = 5
removeongethit = 1
ownpal = 1

[State PlaySnd]
type = PlaySnd
triggerall = var(13) >= -5 ; If enemy's Special Defence level is greater than -5
trigger1 = time = 0        ; When this should activate
value = F15001,1

[State VarAdd]
type = VarAdd
triggerall = var(13) >= -5 ; If enemy's Special Defence level is greater than -5
trigger1 = time = 0        ; When this should activate
v = 13                     ; Stat to reduce
value = -1                 ; Stat Reduction

[State SelfState]
type = SelfState
trigger1 = time >= 1
value = 5000


As for immunities, they only exist as abilities in the chracters themselves in statedef -3. These require you to put the following relative state in statedef -3, although you need two free variables for this to work:

These require you to put the following relative state in statedef -3:

[State VarSet]; Hyper Cutter (Immune to Attack Reduction)
type = VarSet
triggerall = Var(40) >= 1   ; Abilites must be on
trigger1 = roundstate <= 1  ; Activates before the fight begins
v = 4#                      ; Immunity variable
value = var(10)             ; Set to Actual Attack variable

[State VarSet]; Hyper Cutter (Immune to Attack Reduction)
type = VarSet
triggerall = Var(40) >= 1   ; Abilites must be on
triggerall = roundstate >= 2  ; Activates before the fight begins
trigger1 = var(10) < var(4#); Actual Attack must be lower than immunity variable
v = 10                      ; Actual Attack variable
value = var(4#)             ; Set to Immunity variable


These require you to put the following relative state in your attack-boosting statedef, after the attack booster state. If you don't have one, ignore this.

[State VarSet]; Hyper Cutter (Immune to Attack Reduction)
type = VarSet
triggerall = Var(40) >= 1   ; Abilites must be on
trigger1 = var(10) > var(4#); Actual Attack must be higher than immunity variable
v = 4#                      ; Immunity variable
value = var(10)             ; Set to Actual Attack variable


=-==========-==========-==========-=-==========-==========-==========-=-==========-==========-==========-
[Weather Effects]

Pokemon can be affected by various forms of weather, which is summoned by moves, abilities, and certain stages automatically.

The common effects are as follows:

Harsh Sunlight          : Fire moves deal 50% more damage, Water moves deal 50% less damage.
Extremely Harsh Sunlight: Fire moves deal 50% more damage, Water moves deal 0% damage. Used for Primal Groudon.
Rain                    : Water moves deal 50% more damage, Fire moves deal 50% less damage.
Heavy Rain              : Water moves deal 50% more damage, Fire moves deal 0% damage. Used for Primal Kyogre.
Sandstorm               : Boosts Special Defence of Rock-type pokemon by 50% (Implemented within pokemon's states). Damages non-Rock/Ground/Steel type pokemon by 1/16 of their Max HP.
Hail                    : Damages non-Ice type pokemon by 1/16 of their Max HP.
Fog                     : Reduces the accuracy of all pokemon by 30% BEFORE all other accuracy calculations are resolved in "Calculated Hit Rate".

In order to code this, you need to add the following to a move's statedef:

1. Relevant attack states. This is used to summon the weather effect, where the next piece of code will be more useful there. This example is for Sunny Day (Summons Sun for 5 turns):

[State VarSet]
type = VarSet
triggerall = Var(37) != [1,2] ; Checks if weather is not correct
trigger1 = time = 60          ; Time of activation
v = 44                        ; User's own variable as a timer
value = 6                     ; Active turns. Set to 6 since it counts down from the turn you use this.

[State VarSet]
type = VarSet
triggerall = Var(37) != [1,2] ; Checks if weather is not correct
trigger1 = time = 60          ; Time of activation
v = 38                        ; Weather variable to use
value = 1                     ; What weather should be used to inform main weather/terrain detector

[State VarSet]
type = VarSet
trigger1 = time = 62          ; Time of deactivation
v = 38                        ; Weather variable to use
value = 0                     ; Stop informing main weather/terrain detector

The value in the "time" trigger has to be at least two ticks from the time you activate the effect to the time you "deactivate" the effect, like the above code. This is because Mugen's internal code lags behind by 1 tick for player 2, and they may not be able to "see" the weather changes to be affected by them.

2. Relevant statedef -3 states. This is used to keep track of turns on the weather effect, and then turns it off when it expires:

[State VarSet];Sun Time
type = VarSet
trigger1 = var(44) = 1                          ; User's own variable detects if weather is about to end
trigger2 = Var(37) != [1,2]                     ; Checks if weather is not correct
trigger2 = stateno != 530                       ; but only if user is NOT in the relevant state
v = 44                                          ; User's own variable as a timer
value = 0                                       ; Turns timer off

[State VarSet];Sun Time
type = VarSet
trigger1 = var(38) = -1                         ; Checks if Weather setter is turned off
v = 38                                          ; Weather setter for all players
value = 0                                       ; Stop informing main weather/terrain detector

[State VarAdd];Sun Time
type = VarAdd
triggerall = var(1) = var(0)-1 && roundstate = 2; Activates each time the ATB bar fills
trigger1 = var(44) >= 2                         ; Checks if User's own variable has at least 2 turns left
v = 44                                          ; User's own variable as a timer
value = -1                                      ; Timer ticks down each time the ATB bar fills

[State VarSet];Sun Time
type = VarSet
triggerall = var(44) = 1                        ; User's own variable detects if weather is about to end
trigger1 = Var(37) = [1,2]                      ; Checks if weather is correct
v = 38                                          ; Weather setter for all players
value = -1                                      ; Tells main weather/terrain detector to turn weather off


How it works is this: The system knows that whatever value is set that isn't 0 affects the weather for all players. Player 1 is the person who implements the weather for all players, but doesn't directly affect the "current weather" value. Instead, all players use the "Weather Setter by all players" variable. Anything set that isn't 0 will tell player 1 to set the weather to that value. At -1, it erases all weather effects on the field.


=-==========-==========-==========-=-==========-==========-==========-=-==========-==========-==========-
[Item Manipulation]

Pokemon can interact with items using various moves, abilities, and when given to them by their trainers.

There are two variables used for item use in general:

var(20) = Item State, used as a current status for item "stocks"
var(21) = Used Item Effect, used to show what item you used.


How this works is as follows: Each time an item is used, it sends the user into a state that relates to the currently-selected item. While in that state, it sets the variable of what you used earlier so that it reminds the user that they used an item.


In order to code this, you need to add the following to a move's statedef:

1. Relevant states. This is used to 

[State VarSet]
type = VarSet
triggerall = var(20) != 1  ; Checks if weather is not correct
triggerall = var(20) != 3
triggerall = var(20) != 5
triggerall = var(20) != 8
trigger1 = time = 0
v = 20                     ; Item State
value = 8                  ; Set Item State to 8 since 




=-==========-==========-==========-=-==========-==========-==========-=-==========-==========-==========-
[Lifebars]
This is more of a note than anything else. The lifebars are coded into the system and as a result, per character. They're not standard lifebars by any means.
You can still access "life" and "lifemax" triggers like you would in any character.

=-==========-==========-==========-=-==========-==========-==========-=-==========-==========-==========-
[Stats]
At the top of every character's primary CNS file, there's a [Data] block. Values for Life are set here, but note that others need to be set in Statedef -3. In addition, all are accurate to the source. For example:

To accurately set your character's stats, go here: http://bulbapedia.bulbagarden.net and search for your character.
Find the section that says "Stats" and then underneath "Base Stats." Look at the area that says "At lvl. 100", and use the highest values you find.
There's a range of numbers for HP, Attack, Sp.Attack, Defense, and Sp.Defense.

For example, here are Skarmory's stats: http://bulbapedia.bulbagarden.net/wiki/Skarmory#Base_stats
life = 334
attack = 100 ; Keep at 100
defence = 100 ; Keep at 100
power = 0 ; Set to 0, because it's never used.

...and in State -3 goes the rest of the stats:

; Set stats
[State ]
type = Null
trigger1 = fvar(4):=floor((284)*fvar(34)) ; Attack
trigger1 = fvar(5):=floor((196)*fvar(35)) ; Special Attack
trigger1 = fvar(6):=floor((416)*fvar(36)) ; Defense
trigger1 = fvar(7):=floor(((262)*fvar(37))*ifelse(var(21)=16,1.5,1)) ; Special Defense

Did you notice the calculations of Special Defence, shown below?

floor(((###)*fvar(37))*ifelse(var(21)=16,1.5,1))

As of Beta 5, items can influence what you base stats can be. This calculation is used for Assault Vest users (Gain 50% more Sp.Defence). However, this doesn't take into account Rock-types and the weather. To calculate that in addition to items, we use this code:

fvar(7):=floor((((251)*fvar(37))*ifelse(var(37)=5,1.5,1))*ifelse(var(21)=16,1.5,1)) ; Special Defense (For Rock-type and Assault Vest)

=-==========-==========-==========-=-==========-==========-==========-=-==========-==========-==========-
[Type Affinities]
Affinities are type resistances and weaknesses amongst the various pokemon in PCEA.
The system has that actual calculations handled, but there's some setup required first.

Set Pokemon Type:
In State -3 of your character, add this:

; Set Type Weaknesses
[State ]
type = Null
trigger1 = fvar(10):=0.66 ; Normal
trigger1 = fvar(11):=1.5 ; Fire
trigger1 = fvar(12):=1.0 ; Water
trigger1 = fvar(13):=0.44 ; Grass
trigger1 = fvar(14):=1.5 ; Electric
trigger1 = fvar(15):=1.0 ; Ice
trigger1 = fvar(16):=1.0 ; Fighting
trigger1 = fvar(17):=0.0 || 1 ; Poison
trigger1 = fvar(18):=0.0 || 1 ; Ground
trigger1 = fvar(19):=0.66 ; Flying
trigger1 = fvar(20):=0.66 ; Psychic
trigger1 = fvar(21):=0.44 ; Bug
trigger1 = fvar(22):=1.0 ; Rock
trigger1 = fvar(23):=1.0 ; Ghost
trigger1 = fvar(24):=0.66 ; Dragon
trigger1 = fvar(25):=1.0 ; Dark
trigger1 = fvar(26):=0.66 ; Steel
trigger1 = fvar(27):=0.66 ; Fairy
trigger1 = fvar(28):=1.0 ; Freeze Dry
trigger1 = fvar(29):=0.66 ; Flying Press
trigger1 = fvar(32):=1.0 ; Non-Type

These are the type multipliers. Instead of setting of types for pokemon, we set their weaknesses and strengths instead. This data can be found on the pokemon's Bulbagarden page. For example, Skarmory's type modifiers are above and are directly referenced from here: http://bulbapedia.bulbagarden.net/wiki/Skarmory#Type_effectiveness

The Non-Type is a special affinity that is only used for moves that deal typeless damage. For example, Counter/Mirror Coat, and Future Sight (Generation 3) all deal typeless damage, among other moves. Unless otherwise stated, this affinity should be left alone.

When setting the values, use the corresponding values for strength of effectiveness:

:=0.0 || 1 ; 0, Immune/Not Effective At All
:=0.44     ; 1/4, Not very Effective
:=0.66     ; 1/2, Not very Effective
:=1.0      ; Normal Effectiveness
:=1.5      ; 2x, Super Effective
:=2.25     ; 4x, Super Effective

IMPORTANT NOTE: If you're setting an immunity (0.0 multiplier), you must also add "|| 1" to the trigger line. If not, the trigger will not be triggered and pass to the next trigger1s due to the evaluated result being falsy, i.e. 0. Skarmory is immune to Poison and Ground, so this is reflected above.

=-==========-==========-==========-=-==========-==========-==========-=-==========-==========-==========-
[Portraits]

Each character has 3 portraits that need to be set:

9000,0: 
This is the tiny portrait for the select screen. Alignment might seem hard, but it's easier to handle it like this: Make a 36x36 square around the portrait, having the portrait in the center. DO NOT crop it until after it's positioned in Fighter Factory. Don't crop it before then either, for example in Photoshop.
The resource for these can be found here, up to Generation 6: http://veekun.com/dex/downloads , then search for Sprite packs > Others > Pokemon icons.

9000,1:
This is the portrait for the lifebars in-game and should be a size of 40x40. It comes from Pokemon Mystery Dungeon, and must be aligned to 0,0.
The resource for these can be found here, but only up to Generation 4: http://archives.bulbagarden.net/w/index.php?title=Category:Mystery_Dungeon_portraits

9000,2:
This is the large portrait for the select screen, which comes with a copy of the pokemon's moveset and should be at a size of 330x163. For this one, you need to follow the template shown and match up the pokemon's portrait with the middle of the 80x80 square. It must be aligned to 235,0.
The resource for the big portrait can be found here, up to Generation 5: http://veekun.com/dex/downloads , then search for Sprite packs > Main Pokemon sprites, and take your pick from either Generation 4 or 5.

=-==========-==========-==========-=-==========-==========-==========-=-==========-==========-==========-
[Sprites]

*Pokemon Itself*

Each pokemon have a set of sprites for use with this game, but you can't just use any sprites. They have to be from Joshr, the person who sprited most of the pokemon from the Spriters Resource. If you use this, note that your selection is limited by Joshr's choice of pokemon, and that not all pokemon are sprited, so use this as a benchmark for what pokemon can exist in this game.
All resources for this can be found here: http://www.spriters-resource.com/submitter/JoshR691/

If you cannot find a pokemon you want to make, the only alternative is to make them yourself or have others make them for you. Be warned, as the sprites have to maintain a degree of accuracy to both Joshr's style of making pokemon sprites, and be faithful to the pokemon itself. 
JoshR's Deviant Art page has some pokemon drawn by him that aren't on Spriter's Resource, but aren't animated and thus resources for them are scarce. They can be found here: http://joshr691.deviantart.com/

Sprite effects, like flames for a flamethrower, can be whatever fitting effect you want your pokemon to have, but do note that a certain degree of quality should be maintained. The effects made on Ryon and Alexei's pokemon are made using a program called "After Effects". Unless you know how to use it or have quality effects of your own, you may request Alexei to make them for you.
Some effects are already programmed into the game engine itself, within fightfx.sff. Their animation numbers are as follows:


0   : Melee Hit
1   : Fire Hit
2   : Slash
3   : Paralyze Effect
4   : Lightning HitSpark
5   : Poison HitSpark
6   : Heal Effect
40  : Red Boost Effect Decreased
41  : Pink Boost Effect Decreased
42  : Orange Boost Effect Decreased
43  : Yellow Boost Effect Decreased
44  : Blue Boost Effect Decreased
45  : Gray Boost Effect Decreased
46  : Green Boost Effect Decreased
50  : Red Boost Effect Increased
51  : Pink Boost Effect Increased
52  : Orange Boost Effect Increased
53  : Yellow Boost Effect Increased
54  : Blue Boost Effect Increased
55  : Gray Boost Effect Increased
56  : Green Boost Effect Increased
60  : Small ground shockwave
61  : Medium ground shockwave
62  : Large ground shockwave
70  : Light wall-hit shockwave
120 : Small floor dust




To use these, put an F next to the value on any state that requires you to use "anim = ". For example;

-----------------

[State Explod]
type = Explod
trigger1 = 1
anim = F0  ; This is the "Melee Hit" effect.

---------------


*Move Table, Name, Move indicator*

These sprites are required to know what moves you can do and what move is which. 

The resource for the text can be found here: https://www.spriters-resource.com/game_boy_advance/pokemonfireredleafgreen/sheet/45598/ (Agrs' font rip from Fire Red/Leaf Green)
All other resources for this are found within Kung Fu Man's folder in this game's files.

For everything else, you will have to either extract them from other characters, or edit the templates of the sprites to include your text, colours, and what-not. To get an idea on text placement, axis and dimensions, look into other character's files.

=-==========-==========-==========-=-==========-==========-==========-=-==========-==========-==========-
[Cries]

Each character has up to two sound effects for their voice (cries) that can be set:

Group 11,0:
This is reserved for when the pokemon is KO'd, and when they are sent out or win a fight.
All resources for this can be found here: http://veekun.com/dex/downloads , then search for Other files > Pokemon cries.

Group 11,1:
This is when the pokemon is sent out and when they win a fight. This is not necessary to code but if it's used, you can replicate the lower-pitch versions of the sound for when a pokemon is KO'd, and leave this for the healthy sound.
To code this, you will have to make your own intro state. This is as easy as copying the code from common1.cns. Search for both [Statedef 191] and [Statedef 181], copy the entire code, and replace the sound that plays with the "healthy sound".

The rest of the sounds can be whatever fitting effect you want to use. 

=-==========-==========-==========-=-==========-==========-==========-=-==========-==========-==========-

[Status Effect Custom Animation] (Optional)

All pokemon can have their own custom animation implemented for status effects. If set, instead of the pokemon's hurt animation, it will have the pokemon's custom animation to correspond to the current status.

The sleep animation is number 5533.

All animations can be whatever fitting animation you want to use. Remember to add your get-hit collisions to the animation so they can still be hit while having that status.

=-==========-==========-==========-=-==========-==========-==========-=-==========-==========-==========-

[Abilities] (Optional)

All pokemon have abilities that can change the tide of a match. Though there are numerous abilities, as with moves, not all of them can be made as they are in the main games.

Abilities are coded exactly how you would for any effect or moves. Here are some examples of how certain abilities can be made, although this won't tell you how to make each one:

------------------------

1. Snow Cloak: Increases evasion while the weather is Hail.

[State -3];Snow Cloak On
type = VarSet
triggerall = Var(40) >= 1 ; Checks if abilities are turned on
trigger1 = var(37) = 6    ; Checks if weather is correct
fv = 9                    ; Evasion stat
value = 5                 ; Boosts evasion by 2 points

[State -3];Snow Cloak Off
type = VarSet
triggerall = Var(40) >= 1
trigger1 = var(37) != 6
fv = 9
value = 3                 ; Normalizes Evasion

------------------------

2. Rock Head: Prevents recoil damage taken.

[State LifeAdd]
type = LifeAdd
triggerall = Var(40) <= 0                        ; Checks if abilities are turned off
trigger1 = enemynear,var(6)                      ; Checks if nearest foe has taken damage
value = 0-(var(6):=floor(enemynear,var(6)*0.33)) ; Damage calculation is 1/3 of damage dealt
kill = 1                                         ; Causes suicide if life hits 0
persistent = 0
ignorehitpause = 1

------------------------

3. Pure/Huge Power: Doubles Attack stat.

; Set stats
[State Null]
type = Null
trigger1 = fvar(4):=300+(300*var(40)) ; Attack
trigger1 = fvar(5):=300 ; Special Attack
trigger1 = fvar(6):=300 ; Defense
trigger1 = fvar(7):=300 ; Special Defense

------------------------

Abilities are palette specific, and will only turn on with certain palettes. The variable used is var(40), acting as a switch. When making your own pokemon, this can be changed so they can activate under certain difficulty modes or even have them on permanently.

To get an idea as to what ability you can make, you can either check whether the pokemon within this game itself have abilities you're after so you can copy them, or you can seek advice from fellow creators as to how a wanted ability should be coded.

=-==========-==========-==========-=-==========-==========-==========-=-==========-==========-==========-

[Mega Evolution] (Optional)

As of now, there is no code within the system that allows for Mega Evolution. The best you can do is make a separate character as a pokemon that has mega-evolved.

As an example, Charizard would have sprites of its mega-evolved form already added to replace most of his original sprites; only the standing and "taunt" would be left intact. Then, during his intro, the trainer would "mega-evolve" him by "changing" his normal standing sprites into his mega-evolved form's sprites.

Meanwhile, his moveset, abilities, and typing are treated as if you're working on a completely new character. In this case for his X-form, Mega-Charizard X would have his Fire/Dragon typing, his fire, dragon, and other moves you plan to add to him, and abilities and stats he has from mega-evolving. This also lets players choose TWO different Charizards - normal and mega-evolved - to play with.

As with normal sprites, if you cannot find a pokemon you want to make, the only alternative is to make them yourself or have others make them for you.


=-==========-==========-==========-=-==========-==========-==========-=-==========-==========-==========-

[Z-Moves] (Optional)

As with Mega Evolution, there is no code within the system that allows for Z-Moves. The best you can do is make another move with said Z ability, use a free variable that changes properties of moves, and use the "START" command to switch this on or off before you select moves to use (as START is the only command that can be used at any time without selecting a move and during an intro without interrupting it).

As an example, Bellossom would have both the "Bloom Doom" move and any relevant Z-move coded that isn't part of the usual "500,510,520,530" statedef numbers. Then, when selecting moves, pressing START will activate Z-move mode that allows for either Grass-type move to become Bloom Doom, or a defensive move to become their Z-equivalents.


=-==========-==========-==========-=-==========-==========-==========-=-==========-==========-==========-


And that's all there is to it. If everything is set correctly, the pokemon will function as it should with no mugen-based errors. However, if you are stuck with something or otherwise need help, head to this project's forum, which is here: http://mugenguild.com/forum/topics/project-catch-em-all-153640.0.html
